import axios from "axios"
import useMainStore from '@/store/modules/main'

const mainStore = useMainStore()

export function request(config){
  // 1.创建axios实例
  const instance =axios.create(
    {
      baseURL:"http://123.207.32.32:1888/api",
      timeout:5000
    })

  // 2.axios请求拦截器
  instance.interceptors.request.use(config=>{
    mainStore.isLoading = true
    return config
  },err=>{
    console.log(err);
  })

  // // 响应拦截
  instance.interceptors.response.use(res=>{
    mainStore.isLoading = false
    return res.data
  },err=>{
    mainStore.isLoading = false
    console.log(err);
  })

  //3.发送真正的网络请求   instance的返回值本身就是一个promise
  return instance(config)
}